// import { fileURLToPath, URL } from 'node:url'
import { resolve } from 'path'
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import eslintPlugin from 'vite-plugin-eslint'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'

// https://vitejs.dev/config/
export default ({ mode }: any) =>
  defineConfig({
    plugins: [
      vue(),
      eslintPlugin({
        include: ['src/**/*.ts', 'src/**/*.vue', 'src/*.ts', 'src/*.vue']
      }),
      AutoImport({
        resolvers: [ElementPlusResolver()]
      }),
      Components({
        resolvers: [ElementPlusResolver()]
      })
    ],
    resolve: {
      alias: {
        '@': resolve(__dirname, './src')
      }
    },
    server: {
      host: '0.0.0.0',
      cors: true,
      port: 8995,
      open: false //自动打开
      // proxy: {
      //   "^/ccc": {
      //     target: "http://116.62.215.158",
      //     changeOrigin: true, // 允许跨域
      //     rewrite: (path) => path.replace(/^\/ccc/, ""), // 将ccc替换为空
      //   },
      // },
    },
    build: {
      // esbuild 打包更快，但是不能去除 console.log，terser打包慢，但能去除 console.log
      minify: 'terser',
      terserOptions: {
        // 发布删除console
        compress: {
          drop_console: true
        }
      }
    }
  })
